{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "25052736",
   "metadata": {},
   "source": [
    "## 测试基于 clickhouse 的策略管理系统接口\n",
    "\n",
    "---\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8e6293be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:\\Users\\zengb\\.czsc 目录缓存超过1GB，请适当清理。调用 czsc.empty_cache_path() 可以直接清空缓存\n",
      "欢迎使用CZSC！当前版本标识为 0.10.3@20251003\n",
      "\n",
      "任何个人、阶级，其力量归根结底来自自己，无须期盼或感恩于所谓的救世主、大救星。所有救世\n",
      "主、大救星都不过是人造的，连神都是人造的，没有造的人，即使是神，也什么都不是！    \n",
      "\n",
      "--摘自《2006-04-23 18:32 鼓吹救世主、大救星的是真正的精神鸦片！》\n",
      "CZSC环境变量：czsc_min_bi_len = 6; czsc_max_bi_num = 50; \n",
      "C:\\Users\\zengb\\.czsc 目录缓存超过1GB，请适当清理。调用 czsc.empty_cache_path() 可以直接清空缓存\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2025-10-03 21:26:30.508\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36minit_tables\u001b[0m:\u001b[36m261\u001b[0m - \u001b[1mmetas 表创建成功！\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:30.749\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36minit_tables\u001b[0m:\u001b[36m263\u001b[0m - \u001b[1mweights 表创建成功！\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:31.265\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36minit_tables\u001b[0m:\u001b[36m265\u001b[0m - \u001b[1mreturns 表创建成功！\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:31.363\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36minit_latest_weights_view\u001b[0m:\u001b[36m161\u001b[0m - \u001b[1mcs_latest_weights 视图初始化完成\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:31.439\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36minit_latest_weights_view\u001b[0m:\u001b[36m188\u001b[0m - \u001b[1mts_latest_weights 视图初始化完成\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:31.494\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36minit_latest_weights_view\u001b[0m:\u001b[36m198\u001b[0m - \u001b[1mlatest_weights 视图初始化完成\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:31.495\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36minit_latest_weights_view\u001b[0m:\u001b[36m200\u001b[0m - \u001b[1m所有最新持仓权重视图初始化完成\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "sys.path.insert(0, \"A:/ZB/git_repo/waditu/czsc\")\n",
    "import dotenv\n",
    "dotenv.load_dotenv(dotenv_path=\"A:/ZB/git_repo/waditu/czsc/.env\", override=True)\n",
    "\n",
    "import os\n",
    "import czsc\n",
    "import pandas as pd\n",
    "from zoneinfo import ZoneInfo\n",
    "\n",
    "\n",
    "czsc.welcome()\n",
    "\n",
    "database = \"czsc_strategy_test\"\n",
    "tz = ZoneInfo(\"Asia/Shanghai\")\n",
    "\n",
    "## 初始化策略管理数据库\n",
    "\n",
    "czsc.cwc.initialize(database=database)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8ad7a0d",
   "metadata": {},
   "source": [
    "### 策略数据写入\n",
    "\n",
    "---\n",
    "\n",
    "1. 写入策略元数据\n",
    "2. 写入策略持仓权重\n",
    "3. 写入策略日收益\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dbf9ca29",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2025-10-03 21:26:35.525\u001b[0m | \u001b[33m\u001b[1mWARNING \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mset_meta\u001b[0m:\u001b[36m367\u001b[0m - \u001b[33m\u001b[1m策略 测试策略1号 已存在元数据，如需更新请设置 overwrite=True\u001b[0m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'strategy': '测试策略1号', 'base_freq': '日线', 'description': '这是一个测试用的策略', 'author': 'xxx', 'outsample_sdt': Timestamp('2022-01-01 00:00:00+0800', tz='Asia/Shanghai'), 'create_time': Timestamp('2025-10-03 20:24:39+0800', tz='Asia/Shanghai'), 'update_time': Timestamp('2025-10-03 20:24:39+0800', tz='Asia/Shanghai'), 'heartbeat_time': Timestamp('2025-10-03 21:00:03+0800', tz='Asia/Shanghai'), 'weight_type': 'ts', 'status': '实盘', 'memo': ''}\n"
     ]
    }
   ],
   "source": [
    "czsc.cwc.set_meta(\n",
    "    strategy=\"测试策略1号\",\n",
    "    base_freq=\"日线\",\n",
    "    description=\"这是一个测试用的策略\",\n",
    "    author=\"xxx\",\n",
    "    outsample_sdt=\"20220101\",\n",
    "    weight_type=\"ts\",\n",
    "    status=\"实盘\",\n",
    "    memo=\"\",\n",
    "    overwrite=False,\n",
    "    database=database,\n",
    "    tz=tz\n",
    ")\n",
    "\n",
    "mate = czsc.cwc.get_meta(\"测试策略1号\", database=database)\n",
    "print(mate)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7de01236",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2025-10-03 21:26:38.294\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.utils.cache\u001b[0m:\u001b[36mis_found\u001b[0m:\u001b[36m74\u001b[0m - \u001b[1m缓存文件已找到, C:\\Users\\zengb\\.czsc\\generate_klines\\387FD5BE_generate_klines.pkl\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:38.294\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.utils.cache\u001b[0m:\u001b[36mget\u001b[0m:\u001b[36m85\u001b[0m - \u001b[1m正在读取缓存记录，地址：C:\\Users\\zengb\\.czsc\\generate_klines\\387FD5BE_generate_klines.pkl\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:40.029\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36m__send_heartbeat\u001b[0m:\u001b[36m414\u001b[0m - \u001b[1m策略 测试策略1号 发送心跳成功\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:40.580\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mpublish_weights\u001b[0m:\u001b[36m512\u001b[0m - \u001b[1m策略 测试策略1号 最新时间：2025-06-08 00:00:00+08:00\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:40.594\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mpublish_weights\u001b[0m:\u001b[36m523\u001b[0m - \u001b[1m策略 测试策略1号 共 0 条新信号\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:40.596\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mpublish_weights\u001b[0m:\u001b[36m531\u001b[0m - \u001b[1m准备发布 0 条策略信号\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:40.597\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mpublish_weights\u001b[0m:\u001b[36m545\u001b[0m - \u001b[1m完成所有信号发布, 共 0 条\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:40.780\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36m__send_heartbeat\u001b[0m:\u001b[36m414\u001b[0m - \u001b[1m策略 测试策略1号 发送心跳成功\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "dfw = czsc.mock.generate_klines_with_weights()\n",
    "\n",
    "czsc.cwc.publish_weights(df=dfw, strategy=\"测试策略1号\", database=database, tz=tz)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4cf83a26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                dt symbol   returns\n",
      "101479  2025-06-04  total  0.005481\n",
      "101480  2025-06-05  total  0.002237\n",
      "101481  2025-06-06  total  0.003199\n",
      "101482  2025-06-07  total -0.000736\n",
      "101483  2025-06-08  total  0.000000\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2025-10-03 21:26:49.450\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mpublish_returns\u001b[0m:\u001b[36m581\u001b[0m - \u001b[1m策略 测试策略1号 最新时间：2025-06-08 00:00:00+08:00\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:49.467\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mpublish_returns\u001b[0m:\u001b[36m592\u001b[0m - \u001b[1m策略 测试策略1号 共 18 条新日收益\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:49.470\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mpublish_returns\u001b[0m:\u001b[36m600\u001b[0m - \u001b[1m准备发布 18 条策略日收益\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:49.682\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mpublish_returns\u001b[0m:\u001b[36m608\u001b[0m - \u001b[1m完成批次 1, 发布 18 条日收益\u001b[0m\n",
      "\u001b[32m2025-10-03 21:26:49.683\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mczsc.traders.cwc\u001b[0m:\u001b[36mpublish_returns\u001b[0m:\u001b[36m613\u001b[0m - \u001b[1m完成所有日收益发布, 共 18 条\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "wb = czsc.WeightBacktest(dfw, digits=2, fee_rate=0.0)\n",
    "dfr = pd.melt(wb.daily_return.copy(), id_vars=[\"date\"], var_name=\"symbol\", value_name=\"returns\")\n",
    "dfr.rename(columns={\"date\": \"dt\"}, inplace=True)\n",
    "\n",
    "print(dfr.tail())\n",
    "\n",
    "czsc.cwc.publish_returns(df=dfr, strategy=\"测试策略1号\", database=database, tz=tz)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f27495bd",
   "metadata": {},
   "source": [
    "### 读取策略数据\n",
    "---"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "119d367b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>strategy</th>\n",
       "      <th>base_freq</th>\n",
       "      <th>description</th>\n",
       "      <th>author</th>\n",
       "      <th>outsample_sdt</th>\n",
       "      <th>create_time</th>\n",
       "      <th>update_time</th>\n",
       "      <th>heartbeat_time</th>\n",
       "      <th>weight_type</th>\n",
       "      <th>status</th>\n",
       "      <th>memo</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>日线</td>\n",
       "      <td>这是一个测试用的策略</td>\n",
       "      <td>xxx</td>\n",
       "      <td>2022-01-01 00:00:00+08:00</td>\n",
       "      <td>2025-10-03 20:24:39+08:00</td>\n",
       "      <td>2025-10-03 20:24:39+08:00</td>\n",
       "      <td>2025-10-03 21:26:40+08:00</td>\n",
       "      <td>ts</td>\n",
       "      <td>实盘</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  strategy base_freq description author             outsample_sdt               create_time               update_time            heartbeat_time weight_type status memo\n",
       "0   测试策略1号        日线  这是一个测试用的策略    xxx 2022-01-01 00:00:00+08:00 2025-10-03 20:24:39+08:00 2025-10-03 20:24:39+08:00 2025-10-03 21:26:40+08:00          ts     实盘     "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取策略列表\n",
    "\n",
    "dfm = czsc.cwc.get_all_metas(database=database)\n",
    "dfm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9332720c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dt</th>\n",
       "      <th>symbol</th>\n",
       "      <th>weight</th>\n",
       "      <th>strategy</th>\n",
       "      <th>update_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>0.267271</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>AAPL</td>\n",
       "      <td>-0.469111</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>AMZN</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>BTC</td>\n",
       "      <td>-0.921322</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>CSCO</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95841</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>NVDA</td>\n",
       "      <td>0.565681</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95842</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>ORCL</td>\n",
       "      <td>-0.752165</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95843</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>PYPL</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95844</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>SAP</td>\n",
       "      <td>-0.853120</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95845</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>TSLA</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>95846 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                             dt  symbol    weight strategy               update_time\n",
       "0     2010-01-01 00:00:00+08:00  000001  0.267271   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "1     2010-01-01 00:00:00+08:00    AAPL -0.469111   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "2     2010-01-01 00:00:00+08:00    AMZN -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "3     2010-01-01 00:00:00+08:00     BTC -0.921322   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "4     2010-01-01 00:00:00+08:00    CSCO -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "...                         ...     ...       ...      ...                       ...\n",
       "95841 2025-06-08 00:00:00+08:00    NVDA  0.565681   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "95842 2025-06-08 00:00:00+08:00    ORCL -0.752165   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "95843 2025-06-08 00:00:00+08:00    PYPL -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "95844 2025-06-08 00:00:00+08:00     SAP -0.853120   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "95845 2025-06-08 00:00:00+08:00    TSLA -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "\n",
       "[95846 rows x 5 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfw = czsc.cwc.get_strategy_weights(strategy=\"测试策略1号\", database=database)\n",
    "dfw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "587ca930",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dt</th>\n",
       "      <th>symbol</th>\n",
       "      <th>weight</th>\n",
       "      <th>strategy</th>\n",
       "      <th>update_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2023-01-01 00:00:00+08:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>-0.539429</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2023-01-01 00:00:00+08:00</td>\n",
       "      <td>AAPL</td>\n",
       "      <td>-0.477670</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2023-01-01 00:00:00+08:00</td>\n",
       "      <td>AMZN</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2023-01-01 00:00:00+08:00</td>\n",
       "      <td>BTC</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2023-01-01 00:00:00+08:00</td>\n",
       "      <td>CSCO</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15125</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>NVDA</td>\n",
       "      <td>0.565681</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15126</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>ORCL</td>\n",
       "      <td>-0.752165</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15127</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>PYPL</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15128</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>SAP</td>\n",
       "      <td>-0.853120</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15129</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>TSLA</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>15130 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                             dt  symbol    weight strategy               update_time\n",
       "0     2023-01-01 00:00:00+08:00  000001 -0.539429   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "1     2023-01-01 00:00:00+08:00    AAPL -0.477670   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "2     2023-01-01 00:00:00+08:00    AMZN -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "3     2023-01-01 00:00:00+08:00     BTC -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "4     2023-01-01 00:00:00+08:00    CSCO -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "...                         ...     ...       ...      ...                       ...\n",
       "15125 2025-06-08 00:00:00+08:00    NVDA  0.565681   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "15126 2025-06-08 00:00:00+08:00    ORCL -0.752165   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "15127 2025-06-08 00:00:00+08:00    PYPL -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "15128 2025-06-08 00:00:00+08:00     SAP -0.853120   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "15129 2025-06-08 00:00:00+08:00    TSLA -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "\n",
       "[15130 rows x 5 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfw = czsc.cwc.get_strategy_weights(strategy=\"测试策略1号\", database=database, sdt=\"20230101\")\n",
    "dfw"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "86473550",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dt</th>\n",
       "      <th>symbol</th>\n",
       "      <th>returns</th>\n",
       "      <th>strategy</th>\n",
       "      <th>update_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:25:05+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>AAPL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:25:05+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>AMZN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:25:05+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>BTC</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:25:05+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2010-01-01 00:00:00+08:00</td>\n",
       "      <td>CSCO</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:25:05+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101479</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>ORCL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 21:26:49+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101480</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>PYPL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 21:26:49+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101481</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>SAP</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 21:26:49+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101482</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>TSLA</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 21:26:49+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101483</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>total</td>\n",
       "      <td>0.0</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 21:26:49+08:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>101484 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                              dt  symbol  returns strategy               update_time\n",
       "0      2010-01-01 00:00:00+08:00  000001      0.0   测试策略1号 2025-10-03 20:25:05+08:00\n",
       "1      2010-01-01 00:00:00+08:00    AAPL      0.0   测试策略1号 2025-10-03 20:25:05+08:00\n",
       "2      2010-01-01 00:00:00+08:00    AMZN      0.0   测试策略1号 2025-10-03 20:25:05+08:00\n",
       "3      2010-01-01 00:00:00+08:00     BTC      0.0   测试策略1号 2025-10-03 20:25:05+08:00\n",
       "4      2010-01-01 00:00:00+08:00    CSCO      0.0   测试策略1号 2025-10-03 20:25:05+08:00\n",
       "...                          ...     ...      ...      ...                       ...\n",
       "101479 2025-06-08 00:00:00+08:00    ORCL      0.0   测试策略1号 2025-10-03 21:26:49+08:00\n",
       "101480 2025-06-08 00:00:00+08:00    PYPL      0.0   测试策略1号 2025-10-03 21:26:49+08:00\n",
       "101481 2025-06-08 00:00:00+08:00     SAP      0.0   测试策略1号 2025-10-03 21:26:49+08:00\n",
       "101482 2025-06-08 00:00:00+08:00    TSLA      0.0   测试策略1号 2025-10-03 21:26:49+08:00\n",
       "101483 2025-06-08 00:00:00+08:00   total      0.0   测试策略1号 2025-10-03 21:26:49+08:00\n",
       "\n",
       "[101484 rows x 5 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "dfr = czsc.cwc.get_strategy_returns(strategy=\"测试策略1号\", database=database)\n",
    "dfr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "3b30ecee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>dt</th>\n",
       "      <th>symbol</th>\n",
       "      <th>weight</th>\n",
       "      <th>strategy</th>\n",
       "      <th>update_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>000001</td>\n",
       "      <td>0.198232</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>AAPL</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>AMZN</td>\n",
       "      <td>-0.959428</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>BTC</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>CSCO</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>ETH</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>GOOGL</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>IBM</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>INTC</td>\n",
       "      <td>-0.664225</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>META</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>MSFT</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>NFLX</td>\n",
       "      <td>0.098017</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>NVDA</td>\n",
       "      <td>0.565681</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>ORCL</td>\n",
       "      <td>-0.752165</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>PYPL</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>SAP</td>\n",
       "      <td>-0.853120</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2025-06-08 00:00:00+08:00</td>\n",
       "      <td>TSLA</td>\n",
       "      <td>-1.000000</td>\n",
       "      <td>测试策略1号</td>\n",
       "      <td>2025-10-03 20:24:44+08:00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          dt  symbol    weight strategy               update_time\n",
       "0  2025-06-08 00:00:00+08:00  000001  0.198232   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "1  2025-06-08 00:00:00+08:00    AAPL -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "2  2025-06-08 00:00:00+08:00    AMZN -0.959428   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "3  2025-06-08 00:00:00+08:00     BTC -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "4  2025-06-08 00:00:00+08:00    CSCO -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "5  2025-06-08 00:00:00+08:00     ETH -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "6  2025-06-08 00:00:00+08:00   GOOGL -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "7  2025-06-08 00:00:00+08:00     IBM -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "8  2025-06-08 00:00:00+08:00    INTC -0.664225   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "9  2025-06-08 00:00:00+08:00    META -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "10 2025-06-08 00:00:00+08:00    MSFT -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "11 2025-06-08 00:00:00+08:00    NFLX  0.098017   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "12 2025-06-08 00:00:00+08:00    NVDA  0.565681   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "13 2025-06-08 00:00:00+08:00    ORCL -0.752165   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "14 2025-06-08 00:00:00+08:00    PYPL -1.000000   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "15 2025-06-08 00:00:00+08:00     SAP -0.853120   测试策略1号 2025-10-03 20:24:44+08:00\n",
       "16 2025-06-08 00:00:00+08:00    TSLA -1.000000   测试策略1号 2025-10-03 20:24:44+08:00"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dfl  = czsc.cwc.get_latest_weights(database=database)\n",
    "dfl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5d44eaeb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                          dt symbol    weight strategy               update_time\n",
      "12 2025-06-08 01:00:00+09:00   NVDA  0.565681   测试策略1号 2025-10-03 21:24:44+09:00\n",
      "13 2025-06-08 01:00:00+09:00   ORCL -0.752165   测试策略1号 2025-10-03 21:24:44+09:00\n",
      "14 2025-06-08 01:00:00+09:00   PYPL -1.000000   测试策略1号 2025-10-03 21:24:44+09:00\n",
      "15 2025-06-08 01:00:00+09:00    SAP -0.853120   测试策略1号 2025-10-03 21:24:44+09:00\n",
      "16 2025-06-08 01:00:00+09:00   TSLA -1.000000   测试策略1号 2025-10-03 21:24:44+09:00\n",
      "                             dt symbol  returns strategy               update_time\n",
      "16015 2025-06-08 01:00:00+09:00   ORCL      0.0   测试策略1号 2025-10-03 22:26:49+09:00\n",
      "16016 2025-06-08 01:00:00+09:00   PYPL      0.0   测试策略1号 2025-10-03 22:26:49+09:00\n",
      "16017 2025-06-08 01:00:00+09:00    SAP      0.0   测试策略1号 2025-10-03 22:26:49+09:00\n",
      "16018 2025-06-08 01:00:00+09:00   TSLA      0.0   测试策略1号 2025-10-03 22:26:49+09:00\n",
      "16019 2025-06-08 01:00:00+09:00  total      0.0   测试策略1号 2025-10-03 22:26:49+09:00 \n",
      " 16020 2023-01-01 01:00:00+09:00 2025-06-08 01:00:00+09:00\n"
     ]
    }
   ],
   "source": [
    "tz = ZoneInfo(\"Asia/Tokyo\")\n",
    "\n",
    "dfl  = czsc.cwc.get_latest_weights(database=database, tz=tz)\n",
    "print(dfl.tail())\n",
    "\n",
    "dfr = czsc.cwc.get_strategy_returns(strategy=\"测试策略1号\", database=database, tz=tz, sdt=\"20230101\")\n",
    "print(dfr.tail(), \"\\n\", len(dfr), dfr.dt.min(), dfr.dt.max())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "98c3e578",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                          dt symbol    weight strategy               update_time\n",
      "12 2025-06-07 11:00:00-05:00   NVDA  0.565681   测试策略1号 2025-10-03 07:24:44-05:00\n",
      "13 2025-06-07 11:00:00-05:00   ORCL -0.752165   测试策略1号 2025-10-03 07:24:44-05:00\n",
      "14 2025-06-07 11:00:00-05:00   PYPL -1.000000   测试策略1号 2025-10-03 07:24:44-05:00\n",
      "15 2025-06-07 11:00:00-05:00    SAP -0.853120   测试策略1号 2025-10-03 07:24:44-05:00\n",
      "16 2025-06-07 11:00:00-05:00   TSLA -1.000000   测试策略1号 2025-10-03 07:24:44-05:00\n",
      "                             dt symbol  returns strategy               update_time\n",
      "16015 2025-06-07 11:00:00-05:00   ORCL      0.0   测试策略1号 2025-10-03 08:26:49-05:00\n",
      "16016 2025-06-07 11:00:00-05:00   PYPL      0.0   测试策略1号 2025-10-03 08:26:49-05:00\n",
      "16017 2025-06-07 11:00:00-05:00    SAP      0.0   测试策略1号 2025-10-03 08:26:49-05:00\n",
      "16018 2025-06-07 11:00:00-05:00   TSLA      0.0   测试策略1号 2025-10-03 08:26:49-05:00\n",
      "16019 2025-06-07 11:00:00-05:00  total      0.0   测试策略1号 2025-10-03 08:26:49-05:00 \n",
      " 16020 2022-12-31 10:00:00-06:00 2025-06-07 11:00:00-05:00\n"
     ]
    }
   ],
   "source": [
    "tz = ZoneInfo(\"America/Chicago\")\n",
    "\n",
    "dfl  = czsc.cwc.get_latest_weights(database=database, tz=tz)\n",
    "print(dfl.tail())\n",
    "\n",
    "dfr = czsc.cwc.get_strategy_returns(strategy=\"测试策略1号\", database=database, tz=tz, sdt=\"20230101\")\n",
    "print(dfr.tail(), \"\\n\", len(dfr), dfr.dt.min(), dfr.dt.max())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "27e4c9ce",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "CZSC10",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
